<?php
/**
 * Created by PhpStorm.
 * User: 64423
 * Date: 2018/10/31
 * Time: 10:58
 */

namespace app\api\home;


class Category extends Common
{
    // 顶级分类数据
    public function catelog()
    {
        $id = input('get.id',0);
        $list = db('category')->where('parent_id',0)->order('sort_order desc')->select();
        //默认选中第一个
        if($id == 0){
            $id = $list[0]['id'];
        }
        $info = db('category')->where('id',$id)->find();
        $child_list = db('category')->where('parent_id',$id)->order('sort_order desc')->select();
        $info['child_list'] = $child_list;
        $data = [
            'navList' => $list,
            'currentCategory' => $info
        ];
        return _json(0, '执行成功',$data);
    }

    // 顶级分类下的二级数据
    public function current()
    {
        $id = input('get.id',0);
        //选中分类的大图和简介
        $info = db('category')->where('id',$id)->find();
        $child_list = db('category')->where('parent_id',$id)->order('sort_order desc')->select();
        $info['child_list'] = $child_list;
        $data = [
            'currentCategory' => $info,
        ];
        return _json(0, '执行成功',$data);
    }


}